<template>
  <div>
    <el-dialog
      title="批量创建实例"
      :visible.sync="visible"
      width="30%"
      :before-close="onClose">
      <span>实例数量：</span>
      <el-input class="long-input" type="number" :min="0" v-model="inst_count" :max="50" placeholder="请输入需要批量创建的实例数量"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="onClose">取 消</el-button>
        <el-button type="primary" @click="onBatchCreate">确 定</el-button>
      </span>
    </el-dialog>
  </div>

</template>
<script>
import {experimentModel, imageModel} from '@/api/models.js'
import {Message} from 'element-ui'
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    env_id: {
      type: [Number, Number],
      default: 0
    }
  },
  data() {
    return {
      inst_count: 1
    }
  },
  methods: {
    onClose() {
      this.$emit("onClose")
    },
    onBatchCreate() {
      if(this.env_id <= 0) {
        return Message.warning('请选择有效的实验环境');
      }
      experimentModel.instBatchCreate({
        env_id: this.env_id,
        inst_count: parseInt(this.inst_count)
      }, res => {
        Message.success(res.message);
        this.onClose();
        this.$parent.getEnvs();
      }, err => {
        Message.error(err.message);
        this.$parent.getEnvs();
      })
    },
  }
}
</script>